package com.xm9m.ibczy.dsp.https;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by baichuan on 2016/11/22.
 */

public class RequestQueue {

    public static final int POOL_SIZE = 6;

    private static ExecutorService pool;
    private static RequestQueue queue;


    protected RequestQueue() {
        // 新建一个线程池用来执行网络请求
        pool = Executors.newFixedThreadPool(POOL_SIZE);
    }

    public static class RequestQueueBuilder {

        public RequestQueue builder() {
            if (null == queue) {
                synchronized (RequestQueueBuilder.class) {
                    if (null == queue)
                        queue = new RequestQueue();
                }
            }
            return queue;
        }
    }

    public void add(Runnable runnable) {
        if (runnable == null)
            return;
        pool.execute(runnable);
    }

}
